package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.ArchiveTypeInfo;
import com.ruoyi.system.mapper.ArchiveTypeInfoMapper;
import com.ruoyi.system.service.ArchiveTypeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 档案类型基础信息Service实现类
 *
 * @author admin
 * @date 2025-08-23
 */
@Service
public class ArchiveTypeInfoServiceImpl implements ArchiveTypeInfoService {
    @Autowired
    private ArchiveTypeInfoMapper archiveTypeInfoMapper;

    @Override
    public ArchiveTypeInfo selectArchiveTypeInfoById(Long id) {
        return archiveTypeInfoMapper.selectArchiveTypeInfoById(id);
    }

    @Override
    public List<ArchiveTypeInfo> selectArchiveTypeInfoList(ArchiveTypeInfo archiveTypeInfo) {
        return archiveTypeInfoMapper.selectArchiveTypeInfoList(archiveTypeInfo);
    }

    @Override
    public int insertArchiveTypeInfo(ArchiveTypeInfo archiveTypeInfo) {
        return archiveTypeInfoMapper.insertArchiveTypeInfo(archiveTypeInfo);
    }

    @Override
    public List<Map<String, Object>> selectListByName(ArchiveTypeInfo archiveTypeInfo) {
        return archiveTypeInfoMapper.selectListByName(archiveTypeInfo);
    }

    @Override
    public int updateArchiveTypeInfo(ArchiveTypeInfo archiveTypeInfo) {
        return archiveTypeInfoMapper.updateArchiveTypeInfo(archiveTypeInfo);
    }

    @Override
    public int deleteArchiveTypeInfoById(Long id) {
        return archiveTypeInfoMapper.deleteArchiveTypeInfoById(id);
    }

    @Override
    public int deleteArchiveTypeInfoByIds(Long[] ids) {
        return archiveTypeInfoMapper.deleteArchiveTypeInfoByIds(ids);
    }

    /**
     * 批量新增档案类型信息
     */
    @Override
    @Transactional
    public int batchInsertArchiveTypeInfo(List<ArchiveTypeInfo> archiveTypeList) {
        // 设置公共字段
        String username = SecurityUtils.getUsername();
        Date now = new Date();

        for (ArchiveTypeInfo archiveType : archiveTypeList) {
            // 设置创建人、创建时间
            archiveType.setCreateBy(username);
            archiveType.setCreateTime(now);
            // 设置更新人、更新时间
            archiveType.setUpdateBy(username);
            archiveType.setUpdateTime(now);
        }

        // 调用Mapper批量插入
        return archiveTypeInfoMapper.batchInsert(archiveTypeList);
    }

    @Override
    public int deleteArchiveTypeInfo() {
        return archiveTypeInfoMapper.deleteAll();
    }
}